/*
 * @Author: HeAo
 * @Date: 2021-11-05 09:57:43
 * @LastEditTime: 2021-11-05 12:23:36
 * @LastEditors: HeAo
 * @Description:
 * @FilePath: \web2103-2105\web2103code\4-1-Nodejs\day06\init\app\controller\student.js
 * 别乱动！
 */
const { Controller } = require('egg');
const Response = require('../utils/Response')

class StudentController extends Controller {
  async findAll () {
    const { ctx, service } = this
    // 1.获取请求参数
    // 2.调用service
    let students = await service.student.findAll()
    // 3.给出响应
    ctx.body = new Response(20000, '查询成功', students)
  }

  async saveOrUpdate () {
    const { ctx, service } = this
    // 1.接受请求参数
    const student = ctx.request.body
    // 2.调用service并且传递请求参数
    await service.student.saveOrUpdate(student)
    // 3.给出响应
    ctx.body = new Response(20000, '保存成功', null)
  }

  async deleteById () {
    const { ctx, service } = this
    const id = ctx.query.id
    await service.student.deleteById(id)
    ctx.body = new Response(20000, '删除成功', null)
  }

  async pageQuery () {
    const { ctx, service } = this
    const params = ctx.query
    let pageQueryVm = await service.student.pageQuery(params)
    ctx.body = new Response(20000, '查询成功', pageQueryVm)
  }
}

module.exports = StudentController